package com.ruoyi.web.controller.chat;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.robot.domain.ChatRobotSetting;
import com.ruoyi.robot.service.IChatRobotSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/chat/connection")
public class ConnectionController extends BaseController {

    @Autowired
    private IChatRobotSettingService chatRobotSettingService;

    //获取机器人IP
    @GetMapping("/getConnection")
    public AjaxResult getConnection()
    {
        List<ChatRobotSetting> chatRobotSettingList = chatRobotSettingService.selectChatRobotSettingList(new ChatRobotSetting());
        Random random = new Random();
        //随机选择聊天机器人
        int index = random.nextInt(chatRobotSettingList.size());
        return AjaxResult.success(chatRobotSettingList.get(index));
    }

}
